﻿namespace DesignModeConsole.结构型.适配器模式;

/// <summary>
/// 我们需要的接口格式
/// </summary>
public interface ITarget
{
    void F1();

    void F2();

    void Fc();
}
#region 类适配器方式

/// <summary>
/// 同事/第三方提供的接口
/// </summary>
public class Adaptee
{
    public void Fa()
    {
        Console.WriteLine("fa");
    }

    public void Fb()
    {
        Console.WriteLine("fb");
    }

    public void Fc()
    {
        Console.WriteLine("fc");
    }
}

/// <summary>
/// 适配器
/// </summary>
public class Adaptor : Adaptee, ITarget
{
    public void F1()
    {
        Fa();
    }

    public void F2()
    {
        Fb();
    }

    //这里fc不需要实现，直接继承自Adaptee
}
#endregion

#region 对象适配器：基于组合
public class Adaptee2
{
    public void Fa()
    {
        Console.WriteLine("fa");
    }

    public void Fb()
    {
        Console.WriteLine("fb");
    }

    public void Fc()
    {
        Console.WriteLine("fc");
    }
}

public class Adaptor2 : ITarget
{
    private readonly Adaptee2 _adaptee2;
    public Adaptor2(Adaptee2 adaptee2)
    {
        _adaptee2 = adaptee2;
    }

    public void F1()
    {
        _adaptee2.Fa();
    }

    public void F2()
    {
        _adaptee2.Fb();
    }

    public void Fc()
    {
        _adaptee2.Fc();
    }
}

#endregion